<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h2{
            color: red;
        }
        div{
            height: 100px;
            width: 100px;
            background-color: green;
            margin-bottom: 10px;
        }
        button{
            border: 10px solid yellowgreen;
        }
    </style>
</head>

<body>
    <h2>你好，世界</h2>
    <div></div>
    <button>点我啊</button>
    <span>这是一个寂寞的天</span>
    <script>
        document.querySelector('h2').onclick =function(){
            alert('点我啊');
        }
         document.querySelector('div').onclick =function() {
            alert('点我干嘛');
        }
        document.querySelector('button').onclick =function() {
            alert('点你乍得');
        }
    </script>
</body>

</html>